package com.seu.project.seuquiz.model.vo;

import com.seu.project.seuquiz.model.entity.Question;
import com.seu.project.seuquiz.model.entity.UserQuestionMap;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author SoftPto
 * @createDate: 2023-08-12 16:24
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserQuestionVO {

    /**
     * 题目id
     */
    private Long questionId;

    /**
     * 题干
     */
    private String content;

    /**
     * 题目类型（单选/多选/判断/简答等）
     */
    private String questionType;

    /**
     * 类型（比如党史）
     */
    private String type;

    /**
     * 做题总次数
     */
    private Integer totalCnt;

    /**
     * 做对次数
     */
    private Integer correctCnt;


    public static UserQuestionVO toModel(UserQuestionMap userQuestionMap, Question question) {
        return UserQuestionVO.builder()
                .questionId(Long.valueOf(userQuestionMap.getQuestionId()))
                .content(question == null ? "题目已被删除" : question.getContent())
                .questionType(question == null ? "未知" :question.getQuestionType())
                .type(question == null ? "未知" : question.getType())
                .totalCnt(userQuestionMap.getTotalCnt())
                .correctCnt(userQuestionMap.getCorrectCnt())
                .build();
    }
}
